package br.mg.bhe.ftpobre.fs;


/**
 * 
 * @author Aureliano
 */
public class LocalFile {
	
	private static LocalFile upFolder;
	
	private String name;
	private Long size;
	private String path;
	private boolean directory;
	
	public LocalFile() {
		super();
	}
	
	public static LocalFile getUpFolder() {
		if (upFolder != null) {
			return upFolder;
		}
		
		upFolder = new LocalFile();
		upFolder.setDirectory(true);
		upFolder.setName("/..");
		upFolder.setSize((long) -1);
		
		return upFolder;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isDirectory() {
		return directory;
	}
	
	public void setDirectory(boolean directory) {
		this.directory = directory;
	}

	public Long getSize() {
		return size;
	}

	public void setSize(Long size) {
		this.size = size;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (directory ? 1231 : 1237);
		result = prime * result + ((path == null) ? 0 : path.hashCode());
		result = prime * result + ((size == null) ? 0 : size.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		LocalFile other = (LocalFile) obj;
		if (directory != other.directory)
			return false;
		if (path == null) {
			if (other.path != null)
				return false;
		} else if (!path.equals(other.path))
			return false;
		if (size == null) {
			if (other.size != null)
				return false;
		} else if (!size.equals(other.size))
			return false;
		return true;
	}

	@Override
	public String toString() {
		String n = "";
		if (this.name != null) {
			n = this.name;
		} else if (this.path != null) {
			if (!this.path.contains("/")) {
				n = this.path;
			} else {
				n = this.path.substring(this.path.lastIndexOf("/") + 1);
			}
		}
		
		return n;
	}
}